/*
 * 创建日期 2007-12-18
 * 
 * 更改所生成文件模板为 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
package com.ybfenpan.taglib;


import com.ybfenpan.utils.StringUtil;
import org.apache.commons.beanutils.PropertyUtils;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * @author Administrator
 * 
 *         更改所生成类型注释的模板为 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
public class FmtNumToCnTag extends TagSupport {
    private String name;
    private String property;

    /**
     * @return int
     * @throws javax.servlet.jsp.JspException JspException
     */
    public int doStartTag() throws JspException {
        if (name == null || name.equals(""))
            return SKIP_BODY;
        try {
            Object retObj = pageContext.getRequest().getAttribute(name);
            if(null != retObj && null != property){
                retObj = PropertyUtils.getProperty(retObj, property);
            }
            String retHtml = null!=retObj?retObj.toString():"0";
            int num = Integer.parseInt(retHtml);
            retHtml = StringUtil.toChineseNum(num);
            pageContext.getOut().write(retHtml);
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return SKIP_BODY;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public String getProperty() {
        return property;
    }

    public void setProperty(String property) {
        this.property = property;
    }
}
